#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int n,k;
vector<int> edg[N];
int deg[N],cnt[N];
int main(){
  freopen("life.in","r",stdin);
  freopen("life.out","w",stdout);
  ios::sync_with_stdio(false),cin.tie(0);
  cin >> n >> k;
  for(int i = 1, u , v; i < n ; ++ i) cin >> u >> v,edg[u].push_back(v),edg[v].push_back(u),deg[u]++,deg[v]++;
  for(int i = 1; i <= n ; ++ i)cnt[deg[i]]++;
  if(cnt[1] == 2 && cnt[2] == n-2){
    cout << "YES\n" << k << "\n";
  }else{
    cout << "NO\n" << 0 << "\n";
  }

  return 0;
}